package com.anzia.study_5.slice;

import com.anzia.study_5.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.TickTimer;

public class TickTimerSlice extends AbilitySlice {

	private boolean flag = true;

	@Override
	protected void onStart(Intent intent) {
		super.onStart(intent);
		super.setUIContent(ResourceTable.Layout_tick_timer);

		TickTimer tickTimer = (TickTimer) findComponentById(ResourceTable.Id_my_tt);
		tickTimer.setFormat("yyyy-MM-dd hh:mm:ss");
		tickTimer.setBaseTime(0);
		tickTimer.start();

		tickTimer.setClickedListener(component -> {
			if (flag = true) {
				tickTimer.stop();
				flag = false;
			} else {
				tickTimer.start();
				flag = true;
			}
		});

		tickTimer.setTickListener(new TickTimer.TickListener() {
			@Override
			public void onTickTimerUpdate(TickTimer tickTimer) {
				System.out.println(tickTimer.getText());
			}
		});

	}
}
